$(document).ready(function(){
    Handlebars.registerHelper('indexAddOne',function(index,option){
        return parseInt(index) +1;
    });
    Handlebars.registerHelper('compareAge',function(v1,v2,options){
        if(v1>v2){
            return options.fn(this);
        }else{
            return options.inverse(this);
        }
    });
    Handlebars.registerHelper('transAge',function(v){
        if(v == '男'){
            return '男生';
        }else{
            return '女生';
        }
    })
    var data = {
        student:[
            {
                name:'Jellen',
                sex:'女',
                age:11
            },
            {
                name:'Steven',
                sex:'男',
                age:12
            },
            {
                name:'Mona',
                sex:'女',
                age:13
            }
        ]
    };
    var Htable1 = Handlebars.compile($('#table1').html());
    $('#tableList').html(Htable1(data));

    var student = [
        {
            name:'Jellen1',
            sex:'女',
            age:11
        },
        {
            name:'Steven1',
            sex:'男',
            age:11
        },
        {
            name:'Mona1',
            sex:'女',
            age:11
        }
    ];
    var HtableThis = Handlebars.compile($('#tableThis').html());
    $('#tableThisList').html(HtableThis(student));

    var studentDetails = [
        {
            name:'jellen',
            info:['眼睛','鼻子','嘴巴']
        },
        {
            name:'jellen1',
            info:['眼睛','鼻子','嘴巴']
        },{
            name:'jellen1',
            info:['眼睛','鼻子','嘴巴']
        }
    ];
    var tableEach1 = Handlebars.compile($('#tableEach1').html());
    $('#tableEachForEach1').html(tableEach1(studentDetails));

    var tableEach2 = Handlebars.compile($('#tableEach2').html());
    $('#tableEachForEach2').html(tableEach2(studentDetails));

    Handlebars.registerHelper('parentAdd',function(index){
       this._index = parseInt(index)+1;
       return this._index;
    });

    var classStudents = [
        {
            name:'一班',
            students:[
                {
                    name:'jellen1'
                },
                {
                    name:'jellen2'
                },
                {
                    name:'jellen3'
                }
            ]
        },
        {
            name:'二班',
            students:[
                {
                    name:'Mona1'
                },
                {
                    name:'Mona2'
                },
                {
                    name:'Mona3'
                }
            ]
        },
        {
            name:'',
            students:[
                {
                    name:'Mona1'
                },
                {
                    name:'Mona2'
                },
                {
                    name:'Mona3'
                }
            ]
        }
    ];
    var HindexForeach = Handlebars.compile($('#indexForeach').html());
    $('#indexForeachParent').html(HindexForeach(classStudents));

    var HwithTemplate = Handlebars.compile($('#withTemplate').html());
    $('#useWith').html(HwithTemplate(classStudents));

    var HifTemplate = Handlebars.compile($('#ifTemplate').html());
    $('#useIf').html(HifTemplate(classStudents));


    var HcompareTemplate = Handlebars.compile($('#compareTemplate').html());
    $('#useCompare').html(HcompareTemplate(data));

    var studentHome = [
        {
            name:'Jellen',
            age:15,
            home:'<a href="123.com">home</a>'
        },
        {
            name:'Mona',
            age:16,
            home:'<a href="1234.com">home</a>'
        },
        {
            name:'Steven',
            age:14,
            home:'<a href="1235.com">home</a>'
        }
    ];
    var HhtmlTemplate = Handlebars.compile($('#htmlTemplate').html());
    $('#useHtml').html(HhtmlTemplate(studentHome));




});